package com.ywgt.dead;

import java.util.concurrent.TimeUnit;

public class DeadLock {
    public static void main(String[] args) {
        Dead dead=new Dead("A","B");
        Dead dead1=new Dead("B","A");
        new Thread(()->{
            try {
                dead.testA();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"A").start();

        new Thread(()->{
            try {
                dead1.testA();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"B").start();
    }
}

class Dead {
    private String a;
    private String b;
    public Dead(String a, String b) {
        this.a = a;
        this.b = b;
    }
    public synchronized void testA() throws InterruptedException {

        synchronized (a){
            TimeUnit.SECONDS.sleep(2);
            synchronized (b){

            }
        }
    }
}